package com.atguigu.principle.inversion.improve;


/**
 * @author ccc
 * @create 2020-07-09 14:46
 */
public class DependencyInversion {
    public static void main(String[] args) {
        //客户端无需改变
        Person person = new Person();
        person.receive(new Email());

        person.receive(new WeiXin());
    }
}

//定义一个接口
interface IReceiver {
    public String getInfo();
}

class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件信息：hello,world";
    }
}

//增加新的接收方式
class WeiXin implements IReceiver{

    @Override
    public String getInfo() {
        return "微信消息: hello,Ok";
    }
}

// 方式2
class Person {
    //这里我们是对接口的依赖
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}
